﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using TuanAnhPersonalWeb.Models;
namespace TuanAnhPersonalWeb.Classes
{
    public class RolesAccessConsolidator
    {
        TuanAnhEntities db = new TuanAnhEntities();
        public IList<aspnet_Roles> GetAllRoles()
        {
            var list = db.aspnet_Roles.Select(e => e).ToList();
            return list;
        }
        public aspnet_Roles GetRolesById(System.Guid id)
        {
            var data = db.aspnet_Roles.Where(e => e.RoleId == id).Select(e => e);
            return data.Count() > 0 ? data.Single() : null;
        }

        public void CreateNew(aspnet_Roles roles)
        {
            Guid guid = Guid.NewGuid();
            roles.ApplicationId = System.Guid.Parse("6f3045c9-b318-41f9-bd53-a97766381304");
            roles.RoleId = guid;
            roles.LoweredRoleName = roles.RoleName.ToLower();
            db.aspnet_Roles.AddObject(roles);
            SaveChanges();
        }
        public void SaveChanges()
        {
            db.SaveChanges();
        }
    }
}